#-*-cperl-*-

eval 'exec perl $0 $*'
    if 0 ;

=head1 NAME

sgdbtk

=head1 SYNOPSIS

Sgdb: graphic user interface for gnu's gdb.

=head1 DESCRIPTION

gui interface for sgdb: enhanced gui for gdb

=head1 AUTHOR

mostly Josef Ezra.

=head1 COPYRIGHT

version 10.0

Copyright (c) 2002 EMC Corporation

    This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by the
 Free Software Foundation; either version 2 of the License, or (at your
option) any later version.

    This program is distributed in the hope that it will be useful, but
 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

    You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc., 59
Temple Place, Suite 330, Boston, MA  02111-1307 USA

Enjoy - Josef Ezra <jezra@cpan.com> (EMC, 176 south st. Hopkinton, MA)'

=cut

BEGIN { push @INC, ( $0 =~ m[(.*/)] ) } # eval {require FileBin ; $FindBin::Bin } -- too hairy

use 5.6.0 ;
use warnings ;
use strict ;
use integer ;
use bytes ;

# non standard Tk modules
use Tk ;

use Tk::Dialog ;
use Tk::Adjuster ;
use Tk::ROText ;
use Tk::Balloon ;
use Tk::NoteBook ;

use Sgdb::Tk::BrowseEntry ;
use Sgdb::Tk::SuperText ;

sub helpthem_and_exit() { print <<HELPTHEM ;
sgdb [--help|-h] [--flie=myfile] [--target=mytarget] [--pref=myfile]
     [emulname|filename] [ip [director]]

-h --help    : show this message.
-f --file=   : symbol/exec file to load
-t --target= : remote target. might be ip, serial port, etc.
-d --dir=    : direcotr to connect (like D07A) if -t defined
-p --pref=   : load preferences file  (default is ~/.sgdbpref).
-m --mlist=  : load machines ip list (default is ~/.sgdbhosts).
-i --init=   : eval this file at startup (default is ~/.sgdbrc).

-2 --2frames : split sgdb to two windows (small monitor?)

 % sgdb.pl mypath/to/file
would try to load this file

additional standard X11 params are: -bg, -display (-screen), -font (-fn), -fg,
-geometry, -iconic, -motif, -class, -synchronous, -xrm

HELPTHEM
                          exit 0 ;
}

my %p ;
sub parse_arguments {

    Tk::CmdLine::SetArguments () ;
    use Getopt::Long ;
    my @stdoptions = qw/file=s target=s pref=s mlist=s 2frames init=s dir=s help/ ;

    GetOptions \%p, @stdoptions ;

    helpthem_and_exit if $p{help};

    for (@ARGV) {

        if (!$p{target} and /^\d+\.\d+\.\d+\.\d+$/ ) {
            ($p{target}, $_)  = ($_, '')
        }
        elsif (!$p{dir} and /^D\d\d[a-h]$/i ) {
            ($p{dir}, $_) = ($_, '');
        }
        elsif ( !$p{file} and -f ) {
            ($p{file}, $_) = ($_, '')
        }
        elsif ( !$p{file} ) {

            foreach my $file ( "$_", "bin/$_", "bin/$_.elf"
                             ) {
                -f $file or next ;
                ($p{file}, $_) = ($_, '') ;
                last ;
            }
        }
    }

}

BEGIN { parse_arguments () if @ARGV } # we might need arguments for the next uses
#parse_arguments () if @ARGV ;  # 4 arguments debugging

# sgdbtk modules
use Sgdb::Utils qw(:DEFAULT args_set) ; # enable special features (like hook_add)
use Sgdb::Preferences ;                 # and initialize default params
use Sgdb::myImages ;
args_set map {$p{$_} ? "$_=$p{$_}" : '' } keys %p ; %p = () ;

use Sgdb::Preferences ;         # right after Utils (well, logically it is part of it)
use Sgdb::TopMenu ;             # main window's menu
use Sgdb::CommandPrompt;        # allow quick commands
use Sgdb::ControlPanel ;        # tool bars
use Sgdb::PanesWin ;            # global notebook frame
use Sgdb::StatusLine ;          # for short messages and help
use Sgdb::DataPanesWin ;        # live, traced, registers etc.
use Sgdb::TheMainWindow ;       # top frame NOTE: this should be last

start Sgdb::TheMainWindow () or die "could not start main window. ??!!\n" ;

$mainwindow -> afterIdle( [ $mainwindow => 'after',
                            100,
                            [\&hook_run,  'everything-up-and-running']
                            ] ) ;

MainLoop() ;

exit () ;




sub stoppoint {
    no warnings ;
    $DB::single = 1 ;           # Perlon: 'built in' break point when debugging
    warn "hi\n" ;
}

